import React, {Component} from 'react';
import {
    View,Text,TextInput,Button
} from 'react-native';
import {showShort} from '../../util/Toast'
import {LOGIN_REQUEST} from "../../const/actionTypes";

class Login extends React.Component{


    constructor(props) {
        super(props)
        this.state = {
            phone : "",
            password : ""
        }
    }

    render(){


        return (
            <View>
                <TextInput onChangeText={(phone)=>{this.setState({phone})}}  placeholder='账号' />
                <TextInput onChangeText={(password)=>{this.setState({password})}} placeholder='密码' />
                <Button onPress={this.onPress} title={'登录'}>登录</Button>
            </View>
        )
    }

  
    onPress = () => {
        // const canLogin = this.state.phone && this.state.password
        // if(!canLogin){
        //     showShort("请正确填写账号密码信息!")
        //     return;
        // }
        const phone = this.state.phone
        const password = this.state.password
        //进行登录 saga会监听这里
        this.props.dispatch({type:LOGIN_REQUEST,payload:{phone,password}})
        showShort("登录成功!")
        const {navigate} = this.props.navigation
        navigate('Home')
    };




}

export default Login